#ifndef __PlayState_H__
#define __PlayState_H__

#include <Ogre.h>
#include <NxOgre.h>

#include "GameState.h"
#include "DotSceneLoader.h"

#include "Bullet.h"
#include "Player.h"

class PlayState : public GameState
{
public:
	void enter();
	void exit();

	void pause();
	void resume();

	bool keyPressed(const OIS::KeyEvent &arg);
	bool keyReleased(const OIS::KeyEvent &arg);

	bool mouseMoved( const OIS::MouseEvent &arg );
	bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
	bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

	bool processUnbufferedMouseInput(const FrameEvent& evt);
	bool processUnbufferedKeyInput(const FrameEvent& evt);

	bool frameStarted(const Ogre::FrameEvent& evt);
	bool frameEnded(const Ogre::FrameEvent& evt);

	void setupEventHandlers();
	bool handleQuit(const CEGUI::EventArgs& e);
	bool handleCancel(const CEGUI::EventArgs& e);

	void createScene();
	void resetLevel();

	void drawSprites();

	static PlayState* getInstance() { return &mPlayState; }

protected:
	PlayState();

	Ogre::Root *mRoot;
	Ogre::SceneManager* mSceneMgr;
	Ogre::Viewport* mViewport;
	DeviceManager* mDeviceManager;
	GUIManager* mGUIManager;
	OIS::Keyboard* mKeyboard;
	OIS::Mouse* mMouse;
	Ogre::Camera* mCamera;

	bool firstRound;

	// Scene Loader
	DotSceneLoader* mDotSceneLoader;

	// Game GUI
	ChatBox* mChatBox;
	Ogre2dManager* mSpriteManager;

	// Sound Manager
	OgreAL::SoundManager *soundManager;
	OgreAL::Sound *PlayTheme;
	//OgreAL::Sound *Footstep;
	OgreAL::Sound *GunShot;
	OgreAL::Sound *PlayerDie;
	OgreAL::Sound *Victory;

	// Event handlers
	bool mQuit;
	bool mDismiss;
	bool victoryPlayed;

	// Physics
	NxOgre::World *nxWorld;
	NxOgre::Scene *nxScene;

	// Stores all the bullets
	std::list<Bullet*> ammunition;

	// Game Players
	Player* player1;
	Player* player2;

	Ogre::Real currRound;
	int gameCompleted;
	
	Real mMoveSpeed;
	Degree mRotateSpeed;
	float mMoveScale;
	Degree mRotScale;
	Radian mRotX, mRotY;
	Vector3 mTranslateVector;
	Vector3 mTranslateVector2;

	float mBulletTime1;
	float mBulletTime2;

	float mSpriteTimer;

private:
	static PlayState mPlayState;
	Ogre::Real mDelay;
};

#endif
